package com.helloworld.fiberflax;

import net.minecraft.block.BlockCrops;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;

import static com.helloworld.fiberflax.Fiberflax.superflaxItem;

public class BlockFiberflax extends BlockCrops {
    protected BlockFiberflax() {
        super();
        setRegistryName(new ResourceLocation(Fiberflax.MODID,"block_fiberflax"));
    }

    private static final AxisAlignedBB[] FIBERFLAX_AABB = new AxisAlignedBB[] {
            new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.125D, 1.0D),
            new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.5625D, 1.0D)
    };

    protected Item getSeed()
    {
        return Fiberflax.fiberflaxSeed;
    }

    protected Item getCrop()
    {
        return Fiberflax.fiberflaxItem;
    }

    @Override
    public int getMaxAge() {
        return 1;
    }

    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos)
    {
        return FIBERFLAX_AABB[((Integer)state.getValue(this.getAgeProperty())).intValue()];
    }

    @Override
    public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
    {
        super.getDrops(drops, world, pos, state, fortune);
        if (this.isMaxAge(state) && RANDOM.nextInt(50) == 0)
            drops.add(new ItemStack(superflaxItem));
    }
}
